<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-row :gutter="10">
        <el-form-item label="系统单号" prop="code">
          <el-input v-model="queryParams.code" placeholder="请输入系统单号" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="发货单号" prop="relateBill1">
          <el-input v-model="queryParams.relateBill1" placeholder="请输入发货单号" clearable
                    @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="复核状态" prop="recheckStatus">
          <el-select filterable v-model="queryParams.recheckStatus" placeholder="请选择复核状态" clearable>
            <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <MultipleSelect :selectOptions="dict.type.OrderStatus" :mulSelectLoading="false" :mulSelecteds="queryParams.statusArray"
                          @update:updateMultipleSelect="val => queryParams.statusArray = val">
          </MultipleSelect>
<!--          <el-select filterable v-model="queryParams.status" placeholder="请选择订单状态" clearable>-->
<!--            <el-option v-for="dict in dict.type.OrderStatus" :key="dict.value" :label="dict.label" :value="dict.value"/>-->
<!--          </el-select>-->
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="客户类型" prop="customerType">
          <el-select filterable v-model="queryParams.customerType" placeholder="请选择客户类型" clearable>
            <el-option v-for="dict in dict.type.CustomerType" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="目的网点" prop="jcToOrganizationId">
          <el-select clearable filterable v-model="queryParams.jcToOrganizationId" placeholder="请选择目的网点">
            <el-option v-for="dict in dict.type.DB_JC_ORG" :key="dict.value" :label="dict.label"
                       :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="开单日期">
          <el-date-picker v-model="queryParams.daterangeTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
      </el-row>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="success" icon="el-icon-more" size="mini" @click="moreFilterQuery">更多查询</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['order:order:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                   v-hasPermi="['order:order:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['order:order:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['order:order:export']">导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleCustExport"
                   v-hasPermi="['order:order:export']">导出客户订单
        </el-button>
      </el-col>
      <el-col :span="3">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
                   v-hasPermi="['order:order:import']">导入
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-printer" size="mini" @click="handlePrint"
                   :disabled="multiple" v-hasPermi="['order:order:print']">批量打印
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-circle-check" size="mini" @click="openRecheck"
                   :disabled="multiple" v-hasPermi="['order:order:recheck']">批量复核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-circle-check" size="mini" @click="handleBatchConfirm"
                   :disabled="multiple" v-hasPermi="['order:order:confirm']">批量确认
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-s-check" size="mini" @click="handleAbnormal"
                   :disabled="single" v-hasPermi="['order:order:abnormal']">异常修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-copy-document" size="mini" @click="handleCopy"
                   v-hasPermi="['order:order:copy']">复制新建
        </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange"
              @row-dblclick="handleUpdate"
              :summary-method="getSummaries"
              show-summary
              :default-sort = "{prop: 'time', order: 'ascending'}"
              @sort-change="sortChange">
      <el-table-column type="selection" width="55" align="center" fixed/>
      <el-table-column width="100" label="组织机构" align="center" prop="organizationName" fixed/>
      <el-table-column width="150" label="订单号" align="center" prop="orderCode" fixed>
        <template #default="scope">
          <el-tooltip v-if="scope.row.isAbnormal == 1" content="查看异常信息" placement="top">
            <el-tag type="danger" effect="dark" @click="openAbnormal(scope.row)"> {{ scope.row.orderCode }}</el-tag>
          </el-tooltip>
          <span v-else>{{ scope.row.orderCode }}</span>
        </template>
      </el-table-column>
      <el-table-column width="140" label="发货单号" align="center" prop="relateBill1"/>
      <el-table-column width="140" label="客户单号" align="center" prop="relateBill2"/>
      <el-table-column label="开单日期" align="center" prop="orderTime" width="100" sortable="custom" :sort-orders="['descending','ascending']"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="100" sortable="custom" :sort-orders="['descending','ascending']">
        <template #default="scope">
          <dict-tag :options="dict.type.OrderStatus" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="复核状态" align="left" prop="recheckStatus" width="220">
        <template #default="scope">
          <div v-if="scope.row.recheckStatus === 'Y'">
            <div>已复核</div>
            <div>{{ '复核人:' + scope.row.recheckUserName }}</div>
            <div>{{ '复核时间:' + parseTime(scope.row.recheckTime) }}</div>
          </div>
          <div v-else>未复核</div>
        </template>
      </el-table-column>
      <el-table-column width="220" label="客户名称" align="left" prop="customerName">
        <template #default="scope">
          <dict-tag :options="dict.type.CustomerType" :value="scope.row.customerType"/>
          <div>{{ scope.row.customerName }}</div>
        </template>
      </el-table-column>
      <el-table-column width="80" label="是否拆单" align="center" prop="isTake">
        <template #default="scope">
          <dict-tag :options="dict.type.CommIsNot" :value="scope.row.isTake"/>
        </template>
      </el-table-column>
      <el-table-column width="80" label="结算方式" align="center" prop="feeType">
        <template #default="scope">
          <dict-tag :options="dict.type.Clearing" :value="scope.row.feeType"/>
        </template>
      </el-table-column>
      <el-table-column width="140" label="收入确认状态" align="center" prop="isConfirm">
        <template #default="scope">
          <dict-tag :options="dict.type.ConfirmStatus" :value="scope.row.isConfirm"/>
        </template>
      </el-table-column>
      <el-table-column width="150" label="出发运点" align="center" prop="startZoneName"/>
      <el-table-column width="100" label="目的站" align="center" prop="toOrganizationName" sortable="custom" :sort-orders="['descending','ascending']">
        <template #default="scope">
          <span>{{ scope.row.toOrganizationName }}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" label="目的运点" align="center" prop="endZoneName"/>
      <el-table-column width="80" label="交付方式" align="center" prop="handoverType">
        <template #default="scope">
          <dict-tag :options="dict.type.HandoverType" :value="scope.row.handoverType"/>
        </template>
      </el-table-column>
      <el-table-column width="250" label="收货人" align="left" prop="toContactPerson" show-overflow-tooltip>
        <template #default="scope">
          <div>收货人:{{ scope.row.toContactPerson }}</div>
          <div>电话{{ scope.row.toIphone }}</div>
          <div>地址{{ scope.row.toAddress }}</div>
        </template>
      </el-table-column>
      <el-table-column width="140" label="货名" align="center" prop="productName"/>
      <el-table-column width="80" label="件数" align="center" prop="orderNumber"/>
      <el-table-column width="80" label="体积" align="center" prop="orderVolume"/>
      <el-table-column width="80" label="重量" align="center" prop="orderWeight"/>
      <el-table-column width="80" label="计重" align="center" prop="jzWeight"/>
      <el-table-column label="要求发运时间" align="center" prop="planLeaveTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.planLeaveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="要求到达时间" align="center" prop="planArriveTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.planArriveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际发运时间" align="center" prop="factLeaveTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.factLeaveTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际运抵日期" align="center" prop="factArriveTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.factArriveTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column width="80" label="运输方式" align="center" prop="shipmentMethod"/>
      <el-table-column width="80" label="运输性质" align="center" prop="transportPro">
        <template #default="scope">
          <dict-tag :options="dict.type.TransportPro" :value="scope.row.transportPro"/>
        </template>
      </el-table-column>
      <el-table-column label="在途跟踪" align="center" prop="createName">
        <template #default="scope">
          <el-button type="primary" size="mini" @click="openTrack(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="是否超期" align="center" prop="customerIsExceed">
        <template #default="scope">
          <dict-tag :options="dict.type.CommIsNot" :value="scope.row.customerIsExceed"/>
        </template>
      </el-table-column>
      <el-table-column label="是否回单" align="center" prop="isBack">
        <template #default="scope">
          <dict-tag :options="dict.type.CommIsNot" :value="scope.row.isBack"/>
          <div v-if="scope.row.isBack === 1">回单份数: {{ scope.row.backNumber }}</div>
        </template>
      </el-table-column>
      <el-table-column width="120" label="入库区域" align="center" prop="zoneStorerName"/>
      <el-table-column width="100" label="创建人" align="center" prop="createName"/>
      <el-table-column width="100" label="创建时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="修改人" align="center" prop="modifyName"/>
      <el-table-column width="100" label="修改时间" align="center" prop="modifyTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column width="140" label="备注" align="center" prop="orderDescription"/>
      <el-table-column width="120" label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button v-if="scope.row.status == 1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['order:order:edit']">修改
          </el-button>
          <el-button v-else size="mini" type="text" icon="el-icon-tickets" @click="handleUpdate(scope.row)"
                     v-hasPermi="['order:order:edit']">详情
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['order:order:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <el-dialog :close-on-click-modal="false" :title="orderTrackTitle" :visible.sync="orderTrackVisible" width="550px"
               append-to-body>
      <div class="block" style="max-height: 600px; overflow-y: scroll;">
        <el-timeline>
          <el-timeline-item v-for="(item, index) in orderTrackList" :key="index" :timestamp="item.time" placement="top">
            <el-card>
              <h4>{{ item.event }}</h4>
              <p>{{ item.createName }} 提交于 {{ item.time }}</p>
              <div v-if="item.imgUrls">
                <el-image v-for="(img, ind) in item.imgUrls" :key="ind" style="width: 100px; height: 100px;margin: 10px 10px;" :src="img" :preview-src-list="item.imgUrls"/>
              </div>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :close-on-click-modal="false" :title="upload.title" :visible.sync="upload.open" width="400px"
               append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
                 :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
                 :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport"/>
            是否更新已经存在的数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <order-more-query ref="orderMoreQuery" :query-params="queryParams" @ok="handleQuery"></order-more-query>
    <print-batch-code ref="printBatchCode"></print-batch-code>

    <el-dialog :close-on-click-modal="false" title="修改异常" :visible.sync="openAbnormalVisible" width="850px"
               append-to-body>
      <el-table v-loading="abnormalLoading" :data="abnormalList">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-table :data="scope.row.jcAbnormalDetailList">
              <el-table-column label="字段名称" align="center" prop="targer"/>
              <el-table-column label="原有数据" align="center" prop="sourceValue"/>
              <el-table-column label="替换数据" align="center" prop="targerValue"/>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="异常时间" align="center" prop="time" width="180"/>
        <el-table-column label="修改数量" align="center" prop="number"/>
        <el-table-column label="创建人" align="center" prop="createName"/>
        <el-table-column label="修改原因" align="center" prop="description" width="400"/>
      </el-table>

      <pagination
        v-show="abnormalTotal>0"
        :total="abnormalTotal"
        :page.sync="queryAbnormalParams.pageNum"
        :limit.sync="queryAbnormalParams.pageSize"
        @pagination="getListAbnormal"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelAbnormal">取 消</el-button>
      </div>
    </el-dialog>

    <!--    复核订单-->
    <el-dialog title="复核订单" :visible.sync="openRecheckFlag" width="500px" center>
      <el-form ref="recheckForm" :model="recheckForm" :rules="recheckRules" label-width="100px">
        <el-form-item label="订单号">
          <el-input v-model="codes" disabled/>
        </el-form-item>
        <el-form-item label="复核人" prop="recheckUserId">
          <el-select v-model="recheckForm.recheckUserId" filterable clearable remote reserve-keyword placeholder="请输入关键词" :remote-method="remoteUserMethod" :loading="loading">
            <el-option v-for="item in recheckUserOptions" :key="item.userId" :label="item.dept.deptName + '-'+ item.nickName" :value="item.userId" />
          </el-select>
        </el-form-item>
        <el-form-item label="复核时间" prop="recheckTime">
          <el-date-picker clearable v-model="recheckForm.recheckTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择复核时间"
                          style="width: 65%;">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="recheckBatchOrder">确 定</el-button>
        <el-button @click="openRecheckFlag = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listOrder, delOrder, confirmOrder, copyOrders, recheckOrder, listStatistics} from "@/api/order/order";
import OrderTrack from "@/views/order/order/component/orderTrack.vue";
import OrderMoreQuery from "@/views/order/order/component/moreQuery.vue";
import {listOrderTrackByOrderId} from "@/api/order/orderTrack";
import {listOrderAbnormal} from "@/api/extend/abnormal";
import {getToken} from '@/utils/auth'
import PrintBatchCode from './component/printBatchCode.vue';
import {listUser} from "@/api/system/user";
import {parseTime} from "@/utils/ruoyi";
import MultipleSelect from "@/components/MultipleSelect/index.vue";

export default {
  name: "NewOrder",
  components: {MultipleSelect, OrderMoreQuery, OrderTrack, PrintBatchCode},
  dicts: ['Clearing', 'CustomerType', 'OrderStatus', 'sys_yes_no', 'HandoverType', 'ConfirmStatus', 'TransportPro', 'CommIsNot', 'DB_JC_ORG'],
  data() {
    return {
      // 遮罩层
      loading: true,
      orderId: null,
      // 选中数组
      ids: [],
      codes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      statistics: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      moreFilter: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        status: null,
        statuses: null,
        statusArray: [],
        backNumber: null,
        customerIsExceed: null,
        customerName: null,
        customerType: null,
        feeType: null,
        fyTime: null,
        handoverType: null,
        isAbnormal: null,
        isBack: null,
        isBilling: null,
        jsStatus: null,
        number: null,
        orderMileage: null,
        relateBill1: null,
        relateBill2: null,
        relateBill3: null,
        relateBill4: null,
        relateBill5: null,
        salePerson: null,
        shipmentMethod: null,
        isConfirm: null,
        time: null,
        transportPro: null,
        ydTime: null,
        jcCustomerId: null,
        jcOrganizationId: null,
        jcSettlementId: null,
        jcDispatchId: null,
        factArriveTime: null,
        factLeaveTime: null,
        planArriveTime: null,
        planLeaveTime: null,
        jcFromOrganizationId: null,
        jcToOrganizationId: null,
        hxMoney: null,
        hxType: null,
        whxMoney: null,
        jcZoneStoreroomId: null,
        jcEndZoneId: null,
        jcStartZoneId: null,
        isTake: null,
        agent: null,
        qsTime: null,
        qsPerson: null,
        jzWeight: null,
        jcPrescoId: null,
        jsType: null,
        price: null,
        zAmount: null,
        // 时间范围
        daterangeTime: [],
        // 时间范围
        daterangeFactArriveTime: [],
        // 时间范围
        daterangeFactLeaveTime: [],
        // 时间范围
        daterangePlanArriveTime: [],
        // 时间范围
        daterangePlanLeaveTime: [],
      },
      orderTrackVisible: false,
      orderTrackTitle: '订单追踪',
      orderTrackList: [],
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: 'Bearer ' + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/order/order/importNewData',
      },
      abnormalLoading: false,
      openAbnormalVisible: false,
      abnormalList: [],
      abnormalTotal: 0,
      queryAbnormalParams: {
        pageNum: 1,
        pageSize: 10,
        jcOrderId: null,
      },
      openRecheckFlag: false,
      recheckRules: {
        recheckUserId: [
          {required: true, message: '请选择复核人', trigger: 'change'}
        ],
        recheckTime: [
          {required: true, message: '请选择复核时间', trigger: 'change'}
        ]
      },
      recheckForm: {
        recheckUserId: null,
        recheckTime: null
      },
      recheckUserOptions: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    parseTime,
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.queryParams.daterangeTime && '' !== this.queryParams.daterangeTime) {
        this.queryParams.params["beginTime"] = this.queryParams.daterangeTime[0];
        this.queryParams.params["endTime"] = this.queryParams.daterangeTime[1];
      }
      if (null != this.queryParams.daterangeFactArriveTime && '' !== this.queryParams.daterangeFactArriveTime) {
        this.queryParams.params["beginFactArriveTime"] = this.queryParams.daterangeFactArriveTime[0];
        this.queryParams.params["endFactArriveTime"] = this.queryParams.daterangeFactArriveTime[1];
      }
      if (null != this.queryParams.daterangeFactLeaveTime && '' !== this.queryParams.daterangeFactLeaveTime) {
        this.queryParams.params["beginFactLeaveTime"] = this.queryParams.daterangeFactLeaveTime[0];
        this.queryParams.params["endFactLeaveTime"] = this.queryParams.daterangeFactLeaveTime[1];
      }
      if (null != this.queryParams.daterangePlanArriveTime && '' !== this.queryParams.daterangePlanArriveTime) {
        this.queryParams.params["beginPlanArriveTime"] = this.queryParams.daterangePlanArriveTime[0];
        this.queryParams.params["endPlanArriveTime"] = this.queryParams.daterangePlanArriveTime[1];
      }
      if (null != this.queryParams.daterangePlanLeaveTime && '' !== this.queryParams.daterangePlanLeaveTime) {
        this.queryParams.params["beginPlanLeaveTime"] = this.queryParams.daterangePlanLeaveTime[0];
        this.queryParams.params["endPlanLeaveTime"] = this.queryParams.daterangePlanLeaveTime[1];
      }
      if (this.queryParams.statusArray) {
        this.queryParams.statuses = this.queryParams.statusArray.join(",");
      }
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      // 获取统计数据，放入对应列
      this.statistics = {};
      listStatistics(this.queryParams).then(response => {
        this.statistics = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    moreFilterQuery() {
      this.$refs.orderMoreQuery.moreFilterQuery();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.daterangeTime = [];
      this.queryParams.daterangeFactArriveTime = [];
      this.queryParams.daterangeFactLeaveTime = [];
      this.queryParams.daterangePlanArriveTime = [];
      this.queryParams.daterangePlanLeaveTime = [];
      this.resetForm("queryForm");
      this.$refs.orderMoreQuery.resetQuery();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.codes = selection.map(item => item.orderCode)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    sortChange(row) {
      const { prop, order } = row
      this.queryParams.orderByColumn = prop
      this.queryParams.isAsc = order === 'descending' ? 'desc' : 'asc'
      this.handleQuery();
    },
    handleAdd() {
      /** 打开授权表弹窗 */
      this.$tab.openPage("新增订单", "/product/order/order-edit/add");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.orderId = row.orderId || this.ids
      this.$tab.openPage("修改订单", "/product/order/order-edit/edit/" + this.orderId);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.orderId || this.ids;
      const codes = row.code || this.codes;
      this.$modal.confirm('是否确认删除订单管理编号为"' + codes + '"的数据项？').then(function () {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `内部订单_${new Date().getTime()}.xlsx`)
    },
    /** 导出按钮操作 */
    handleCustExport() {
      this.download('order/order/exportCust', {
        ...this.queryParams
      }, `客户订单_${new Date().getTime()}.xlsx`)
    },
    openTrack(row) {
      this.orderTrackVisible = true
      this.orderTrackList = []
      /** 查询订单追踪列表 */
      this.loading = true;
      listOrderTrackByOrderId(row.orderId).then(response => {
        this.loading = false;
        this.orderTrackList = response.data;
        // 处理图片地址
        if (this.orderTrackList.length > 0) {
          this.orderTrackList.forEach(item => {
            if (item.imgs) {
              // 每个图片地址都加上baseUrl
              item.imgUrls = item.imgs.split(',').map(d => process.env.VUE_APP_BASE_API + d)
            }
          })
        }
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = '导入'
      this.upload.open = true
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('order/order/importNewTemplate', {}, `order_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert('<div style=\'overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;\'>' + response.msg + '</div>', '导入结果', {dangerouslyUseHTMLString: true})
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    handlePrint() {
      this.$refs.printBatchCode.openDialog(this.ids);
    },
    openRecheck() {
      this.openRecheckFlag = true;
      this.resetForm("recheckForm");
    },
    remoteUserMethod(query) {
      if (query !== '' && query.length >= 1) {
        this.loading = true;
        this.recheckUserOptions = [];
        const params = {
          nickName: query,
          pageSize: 10,
          pageNum: 1
        }
        listUser(params).then(response => {
          this.recheckUserOptions = response.rows
          this.loading = false
        })
      } else {
        this.recheckUserOptions = [];
      }
    },
    recheckBatchOrder() {
      const recheckData = {
        ids: this.ids,
        recheckUserId: this.recheckForm.recheckUserId,
        recheckTime: this.recheckForm.recheckTime
      }
      recheckOrder(recheckData).then(response => {
        this.getList();
        this.openRecheckFlag = false;
        this.$modal.msgSuccess("确认成功！");
      });
    },
    handleBatchConfirm() {
      var ids = this.ids;
      const codes = this.codes;
      this.$modal.confirm('是否需要确认订单管理编号为"' + codes + '"的数据项？').then(function () {
        return confirmOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("确认成功！");
      }).catch(() => {
      });
    },
    handleAbnormal() {
      this.$tab.openPage("异常修改", "/product/order/order-edit/abnormal/" + this.ids);
    },
    handleCopy() {
      var ids = this.ids;
      const codes = this.codes;
      this.$modal.confirm('是否需要复制订单管理编号为"' + codes + '"的数据项？').then(function () {
        return copyOrders(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("复制成功！");
      }).catch(() => {
      });
    },
    openAbnormal(row) {
      this.abnormalList = []
      /** 查询订单异常修改列表 */
      this.queryAbnormalParams.jcOrderId = row.orderId
      this.getListAbnormal()
      this.openAbnormalVisible = true
    },
    getListAbnormal() {
      this.abnormalLoading = true;
      listOrderAbnormal(this.queryAbnormalParams).then(response => {
        this.abnormalLoading = false;
        this.abnormalList = response.rows;
        this.abnormalTotal = response.total;
      })
    },
    cancelAbnormal() {
      this.openAbnormalVisible = false
      this.queryAbnormalParams.jcOrderId = null
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];

      columns.forEach((column, index) => {
        if (index === 1) {
          sums[index] = '合计';
          return;
        }
        if (index === 2) {
          sums[index] = this.statistics.order_count;
        }
        if (index === 18) {
          sums[index] = this.statistics.order_number;
        }
        if (index === 19) {
          sums[index] = this.statistics.order_weight;
        }
        if (index === 20) {
          sums[index] = this.statistics.order_volume;
        }

      });
      return sums;
    }
  }
};
</script>
